package com.szx.kaihei.Converts;

import com.szx.kaihei.Enums.CaptchaType;
import com.szx.kaihei.exceptions.CustomException;
import com.szx.kaihei.exceptions.ExceptionEnums;
import org.springframework.core.convert.converter.Converter;

public class EnumConvert implements Converter<String, CaptchaType> {
    @Override
    public CaptchaType convert(String source) {
        for (CaptchaType value : CaptchaType.values()) {
            if (value.getType() == Integer.parseInt( source)) {
                return value;
            }
        }
        throw new CustomException(ExceptionEnums.PARAM_ERROR);
    }
}
